<template>
  <div class="app-container" style="position:relative">
    <!-- 查询条件 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="房主" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入房主名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="聊天室名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入聊天室名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="房间状态" prop="name">
        <el-select v-model="queryParams.status" placeholder="请选择房间状态" clearable style="width: 240px">
          <!-- 绑定下拉框值， -->
          <el-option v-for="dict in dict.type.pcj_chat_group_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['pcj:chatGroup:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['pcj:chatGroup:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['pcj:chatGroup:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 表格内容 -->
    <el-table border v-loading="loading" :data="chatGroupList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="房主" width="120" align="left" prop="userName" />

      <el-table-column label="房间类型" width="120" align="left" prop="groupType">
        <template slot-scope="scope">
          {{ handleGroupTypeValue(scope.row.groupType) }}
        </template>
      </el-table-column>
      <el-table-column label="房间名称" width="250" align="left" prop="name" />
      <el-table-column label="房间创建时间" width="180" align="left" prop="beginTime" />
      <el-table-column label="房间结束时间" width="180" align="left" prop="endTime" />
      <!-- <el-table-column label="聊天室图标" width="150" align="left" prop="icon"/> -->
      <el-table-column label="状态" width="80" align="center" prop="status">
        <!-- 用平台方法回填字典类型值 -->
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pcj_chat_group_status" :value="scope.row.status" />
        </template>
      </el-table-column>

      <el-table-column label="总人数" width="120" align="center" prop="userNum" />
      <el-table-column label="描述" width="250" align="left" prop="remark" />

      <!-- fixed = "right" 固定操作列 -->
      <el-table-column fixed="right" label="操作" width="120" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['pcj:chatGroup:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['pcj:chatGroup:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
//引入当前页需要发送的请求
import { listChatGroup, delChatGroup } from "@/api/pcj/chatGroup";
import { tbDict } from "../../../api/utils/msUtils.js";

//引入获取字典的方法
export default {
  name: "PcjChatGroup",
  //存放引入其他页面的组件名称
  components: {},
  //获取字典-平台字典用法
  dicts: ["pcj_chat_group_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedPcjChatGroupUser: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 聊天室-基本信息表格数据
      chatGroupList: [],
      // 聊天室-人员表格数据
      pcjChatGroupUserList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        name: null,
        status: null,
        beginTime: null,
        endTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      //房间状态字典值
      pcjChatGroupStatusDic: [],
      //打开编辑页面
      editWin: false,
      //编辑表格数据
      editForm: {},
      //聊天室类型
      chatGoupTypeDic: []
    };
  },

  //最新执行，页面dom元素还未初始化
  created() {
    this.getList();

  },
  //进入页面的初始化方法在这写，此时dom元素已初始化结束，在created方法之后执行
  mounted() {
    tbDict("pcjChatGroupType").then(res => {
      this.chatGoupTypeDic = res;
    });
  },
  methods: {
    //回填字典值
    handleGroupTypeValue(e) {
      for (var i = 0; i < this.chatGoupTypeDic.length; i++) {
        if (this.chatGoupTypeDic[i].value == e) {
          return this.chatGoupTypeDic[i].label;
        }
      }},

      /** 查询聊天室-基本信息列表 */
      getList() {
        this.loading = true;
        listChatGroup(this.queryParams).then(response => {
          this.chatGroupList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        //打开编辑页面，path路径在/src/route/index.js里面配置,query为参数主要传入id和操作类型opt
        this.$router.push({
          path: "/pcj/pcjChatGroupForm",
          query: {
            opt: "add",
          }
        });
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        const id = row.id || this.ids;
        //打开编辑页面，path路径在/src/route/index.js里面配置
        this.$router.push({
          path: "/pcj/pcjChatGroupForm",
          query: {
            opt: "edit",
            id: id
          }
        });
      },

      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal
          .confirm('是否确认删除聊天室-基本信息编号为"' + ids + '"的数据项？')
          .then(function () {
            return delChatGroup(ids);
          })
          .then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          })
          .catch(() => { });
      },
      //子表信息放到编辑页面
      // /** 聊天室-人员序号 */
      // rowPcjChatGroupUserIndex({ row, rowIndex }) {
      //   row.index = rowIndex + 1;
      // },
      // /** 聊天室-人员添加按钮操作 */
      // handleAddPcjChatGroupUser() {
      //   let obj = {};
      //   obj.createId = "";
      //   obj.updateId = "";
      //   obj.remark = "";
      //   obj.userId = "";
      //   obj.status = "";
      //   obj.entryTime = "";
      //   this.pcjChatGroupUserList.push(obj);
      // },
      // /** 聊天室-人员删除按钮操作 */
      // handleDeletePcjChatGroupUser() {
      //   if (this.checkedPcjChatGroupUser.length == 0) {
      //     this.$modal.msgError("请先选择要删除的聊天室-人员数据");
      //   } else {
      //     const pcjChatGroupUserList = this.pcjChatGroupUserList;
      //     const checkedPcjChatGroupUser = this.checkedPcjChatGroupUser;
      //     this.pcjChatGroupUserList = pcjChatGroupUserList.filter(function(item) {
      //       return checkedPcjChatGroupUser.indexOf(item.index) == -1;
      //     });
      //   }
      // },
      // /** 复选框选中数据 */
      // handlePcjChatGroupUserSelectionChange(selection) {
      //   this.checkedPcjChatGroupUser = selection.map(item => item.index);
      // },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "pcj/chatGroup/export",
          {
            ...this.queryParams
          },
          `chatGroup_${new Date().getTime()}.xlsx`
        );
      }
    }
  };
</script>
